<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<link rel="stylesheet" href="${ctx}/page/member/css/orders.css" />
<div class="panel panel-default">
	<div class="panel-heading">
		<ul class="nav nav-pills nav-justified" role="tablist">
			<li role="presentation" class="<c:if test="${status eq 0}">active</c:if>"><a href="${ctx}/memberCenter/memberOrders?status=0">待付款</a></li>
			<li role="presentation" class="<c:if test="${status eq 1}">active</c:if>"><a href="${ctx}/memberCenter/memberOrders?status=1">待发货</a></li>
			<li role="presentation" class="<c:if test="${status eq 2}">active</c:if>"><a href="${ctx}/memberCenter/memberOrders?status=2">待收货</a></li>
			<li role="presentation" class="<c:if test="${status eq 3}">active</c:if>"><a href="${ctx}/memberCenter/memberOrders?status=3">已完成</a></li>
		</ul>
	</div>
	<div class="orders">
		<c:forEach items="${orderPage.list}" var="order">
			<div class="panel panel-success">
				<div class="panel-heading">
					<fmt:formatDate value="${order.createTime}" type="both"
						pattern="yyyy-MM-dd HH:mm:ss" />
					<span class="pull-right">订单号:${order.orderNo}</span>
				</div>
				<div class="panel-body">
					<table class="table">
						<thead>
							<tr>
								<th>商品</th>
								<th>收货人</th>
								<th>金额</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
							<tr>
								<td>
									<c:forEach items="${order.items}" var="orderItem">
										<div class="media">
											<div class="media-left">
												<a href="${ctx}/product/${orderItem.product.id}"> 
													<img src="${orderItem.product.smallImage}" class="avatar">
												</a>
											</div>
											<div class="media-body media-middle">
												<a style="color: #333" class="title" href="${ctx}/product/${orderItem.product.id}">
													<h5 class="media-heading">${orderItem.product.name}</h5>
												</a>
												<small class="productInfo">
													<span class="hidden-sm hidden-xs">规格:${orderItem.productSkuRelation.skuValue1}${orderItem.productSkuRelation.skuValue2}</span> 
														&nbsp&nbsp 
													<span class="hidden-sm hidden-xs">单价:<fmt:formatNumber type="number" value="${orderItem.productSkuRelation.price}" pattern="0.00" maxFractionDigits="2"/></span> 
														&nbsp&nbsp 
													<span class="hidden-sm hidden-xs">数量:${orderItem.counts}</span>
														&nbsp&nbsp 
													<span class="hidden-sm hidden-xs">小计:<fmt:formatNumber type="number" value="${orderItem.value}" pattern="0.00" maxFractionDigits="2"/></span>
												</small>
												<c:if test="${order.status eq 3 && orderItem.commentStatus eq 0}">
													<p>
														<a href="${ctx}/order/productComment?orderNo=${order.orderNo}&productId=${orderItem.product.id}">评价晒单</a>
													</p>
												</c:if>
											</div>
										</div>
									</c:forEach>
									</td>
								<td>${order.receiveName}</td>
								<td>&yen<fmt:formatNumber type="number" value="${order.value}" pattern="0.00" maxFractionDigits="2"/></td>
								<td>
									<c:if test="${order.status eq 0}">
										<p>
											<a href="${ctx}/order/orderPay?orderNo=${order.orderNo}">去支付</a>
										</p>
										<p>
											<a href="javascript:;" onclick="cancelOrder('${order.orderNo}')">取消订单</a>
										</p>
									</c:if>
									<c:if test="${order.status eq 1}">
										<p>
											<a href="javascript:;" onclick="distributeCall('${order.orderNo}')">提醒发货</a>
										</p>
									</c:if>
									<c:if test="${order.status eq 2}">
										<p>
											<a href="#">查看物流</a>
										</p>
									</c:if>
									<c:if test="${order.status eq 3}">
										<p>
											<a target="_blank" href="http://wpa.qq.com/msgrd?v=3&uin=1046566144&site=qq&menu=yes">联系客服</a>
										</p>
									</c:if>
									<c:if test="${order.status eq 4}">
										<p style="color: #f00">已取消</p>
									</c:if>
								</td>
							</tr>
						</tbody>
					</table>
					收货地址：${order.receiveAddress}
					<c:if test="${order.remark ne null}">
						<p></p>
						备&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp注：${order.remark}
					</c:if>
				</div>
			</div>
		</c:forEach>
	</div>
</div>

<script type="text/javascript">
	function cancelOrder(orderNo){
		$.ajax({
			type : 'POST',
			url : ctx + '/order/cancelOrder.do',
			data : {
				orderNo : orderNo
			},
			dataType : 'json',
			timeout : 30000,
			context : $('body'),
			success : function(data) {
				if (data.code == "ok") {
					window.location.reload();
				} else {
					showTip2(data.msg);
				}
			},
			error : function(xhr, type) {
				showTip2('提交失败!');
			}
		});
	}
	
	/*提醒发货*/
	function distributeCall(orderNo){
		$.ajax({
			type : 'POST',
			url : ctx + '/order/distributeCall.do',
			data : {
				orderNo : orderNo
			},
			dataType : 'json',
			timeout : 30000,
			context : $('body'),
			success : function(data) {
				if (data.code == "ok") {
					showTip2("提醒发货成功！");
				} else {
					showTip2(data.msg);
				}
			},
			error : function(xhr, type) {
				showTip2('提交失败!');
			}
		});
	}
</script>
